function CheckLogin_Exc(fun){
	    LOGINSTEP=fun,
        $.ajax({url: "/index.php/user/box/login",
            success: function (data) {
                if (data == "200") {
					 eval(LOGINSTEP)
				}else{
					user.userNotLogin('您需要先登录才能进行此操作!');
					return false;
				}
            },
            error: function () {
                Alert("请求超时，请重试!");
            }
        });
}

var FAV={
    IsHide:0,
	SetIsHide:function(auid){this.IsHide=auid},
    Boxid:0,Musicid:0,
    SetBoxid:function(curid,curname){this.Boxid=curid;$("#selid").html(curname);
 		$("#selboxct ul").each(function(){
  			 if(this.id=="box"+curid){this.className="selboxctcls"}
			 else{this.className=""}
		});
	
	},
    SetMusicid:function(curyid){this.Musicid=curyid},
    Hide: function(){layer.close(FAV.layname);},

	SelFav:function(id){
	        $.ajax({url: "/index.php/user/box/fav?action=selbox&musicid=" + id, success: function (data) {
                var reobj = data;
                if (reobj.Result == 200) {
			   		FAV.SetMusicid(id);
					var selhtml=""
					selhtml=selhtml+"<div class='favpad' id='favct'><div class='favmusicname'>"+reobj.MusicName+"</div>"
					selhtml=selhtml+"<div class='selbox'>收藏到：<span id='selid'></span></div><div id='selboxct'>"
					var exeu="";
					var selboxid,selboxname
					for (var i=0;i<reobj.Total;i++){
						if(i==reobj.Total-1){selboxid=reobj.FavList[i].ID;selboxname=reobj.FavList[i].Cname}
 						selhtml=selhtml+"<ul id='box"+reobj.FavList[i].ID+"'><a href=\"javascript:void(0)\" onclick=\"FAV.SetBoxid("+reobj.FavList[i].ID+",'"+reobj.FavList[i].Cname+"')\">"+reobj.FavList[i].Cname+"<span>("+reobj.FavList[i].Counts+")</span></a></ul>"	
					}
					selhtml=selhtml+"</div>"
					selhtml=selhtml+"<div class='favaddmenu'><input name=\"boxname\" type=\"text\" id=\"boxname\" size=\"50\" maxlength=\"50\" class='favinput' placeholder=\"新增音乐盒名称4-12位字符\"/>";
					selhtml=selhtml+"<input type=\"button\" name=\"button\" id=\"button\" value=\"添加并使用\" onclick=\"FAV.AddBox()\" class='favbutton' /></div>"
					selhtml=selhtml+"<div class='favcontorl' ><ul><input type=\"button\" name=\"button\" id=\"button\" value=\"确定收藏\" class='rebutton' onclick=\"FAV.Save()\"/><input type=\"button\" name=\"button\" id=\"button\" value=\"取消收藏\" class='huibutton' onclick=\"FAV.Hide()\"/></ul><ul id='tshtml'></ul></div></div>"
                    divct = '<div id="favbox" >';
                    divct += '<ul><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>';
                    divct += '<td id="sccontent">' + selhtml + '</td>';
                    divct += '</tr></table></ul></div>';
                    FAV.layname = layer.open({
                        type: 1,
                        title: "加入音乐盒",
                        skin: 'layui-layer-rim', //加上边框
                        area: ['500px', '340px'], //宽高
                        content: divct
                    });
					FAV.SetBoxid(selboxid,selboxname);
			}
		}});
	},
	ShowMsg:function(num,curstr){
		 $("#tshtml").html("<div class='e"+num+"'>"+curstr+"</div>")
	},
	Loading:function(){
		 $("#tshtml").html("<img src='/res/home/images/lazyload.gif'>");
	},
	AddBox:function(){
		this.Loading()
		boxname=$("#boxname").val()
		if (boxname.length<4 || boxname.length>12){
			this.ShowMsg(0,"音乐盒名称不合规范(4-12)位!")
			return false;
		}
		if (escape(boxname).indexOf( "%u" )<0){
			this.ShowMsg(0,"音乐盒名称必须有中文!")
			return false;
		}
        $.ajax({url: "/index.php/user/box/boxclass?action=addsave&cname="+unescape(boxname),
            success: function (data) {
                var reobj = data;
                switch (reobj.Result) {
                    case 101:
                        FAV.ShowMsg(0, "音乐盒名称不合规范(4-12)位!");
                        break;
                    case 102:
                        FAV.ShowMsg(0, "您最多只能创建10个音乐盒!");
                        break;
                    case 200:
                        layer.close(FAV.layname);
                        var thisid = FAV.Musicid;
                        FAV.SelFav(thisid);
                    default :
                }
            }
        });
	},
	Save: function () {
        this.Loading();
        var musicid = this.Musicid;
        var boxid = this.Boxid;
        $.ajax({url: "/index.php/user/box/fav_addsave?action=addfav&musicid=" + musicid + "&boxid=" + boxid, success: function (data) {
                var reobj = data;
                switch (reobj.Result) {
                    case 101:
                        FAV.ShowMsg(0, reobj.Info)
                        break;
                    case 200:
                        layer.close(FAV.layname);
                        if (reobj.Result == 200) {
                            var htmls = '' + reobj.MusicName + "已收藏成功！<a href=/user/box/lists/" + boxid + " style='color:green'>查看</a>";
                            Alertok(htmls, 1)
                        } else {
                            Alert(reobj.Info)
                        }
                        break;
                    default :
                }
            }, error: function () {
                Alert("请求超时，请重试!");
                FAV.Hide();
            }
        });
    },
	Hide: function () {
        layer.close(FAV.layname);
    }
}
